# -*- coding: utf-8 -*-

class AnalysisManager:
    def __init__(self, db):
        self.db = db

    def analyze_by_class(self, class_name):
        students = self.db.get_students_by_class(class_name)
        if not students:
            return "没有找到该班级的学生数据"
        scores = [student[4] for student in students]
        avg_score = sum(scores) / len(scores)
        return f"班级 {class_name} 的平均成绩为: {avg_score:.2f}"

    def analyze_by_student(self, name):
        students = self.db.get_student_by_name(name)
        if not students:
            return "没有找到该学生的数据"
        result = f"学生 {name} 的成绩:\n"
        for student in students:
            result += f"科目: {student[3]}, 成绩: {student[4]}\n"
        return result
